package twinb;

import ecologylab.xml.ElementState;
import ecologylab.xml.xml_inherit;
import ecologylab.xml.ElementState.xml_tag;
import winterwell.jtwitter.Twitter.User;

@xml_inherit
@xml_tag("user")
public class Person extends ElementState
{
    // xml data
    @xml_leaf
    public String id;

    @xml_leaf
    public String name;

    @xml_leaf
    public String portal;

    @xml_leaf
    public String screenName;

    @xml_leaf
    public String url;

    @xml_leaf
    public String friendsCount;

    @xml_leaf
    public String followersCount;

    @xml_leaf
    public String createdAt;

    @xml_leaf
    public String following;

    // internal data
    static double wRep = 1.0, wRtw = 1.0, wFlw = 1.0;

    public User   user;

    public int    score, rep, rtw, flw;

    public double pi;

    public Person(User user)
    {
        this.id = String.valueOf(user.getId());
        this.name = user.getName();
        this.screenName = user.getScreenName();
        this.portal = user.getProfileImageUrl().toString();
        this.url = "http://twitter.com/" + this.screenName;
        this.friendsCount = String.valueOf(user.getFriendsCount());
        this.followersCount = String.valueOf(user.getFollowersCount());
        this.createdAt = user.getCreatedAt().toString();
        this.following = String.valueOf(user.isFollowing());

        this.user = user;
        this.score = 0;
        this.rep = 0;
        this.rtw = 0;
        this.pi = 0;
        this.flw = 0;
    }

    public User getUser()
    {
        return this.user;
    }

    public void addRep()
    {
        this.rep += 1;
    }

    public void addRtw()
    {
        this.rtw += 1;
    }

    public double getPi()
    {
        this.updatePi();
        return this.pi;
    }

    public void updatePi()
    {
        this.flw = this.user.followersCount;
        this.pi = this.rep * wRep + this.rtw * wRtw + Math.log(this.flw) * wFlw;
    }
    //Problem: conflict with the String id
    public long getId()
    {
        return this.user.id;
    }

}
